export {}
// 1.写函数时的重要提示
function sum(a: number, b: number): number {
  return a + b
}
console.log(sum(1, 2))

const sum1 = (a: number, b: number): number => a + b
console.log(sum1(1, 3))

type sum2 = (a: number, b: number) => number
const sum21: sum2 = (sum1, sum2) => sum1 + sum2
console.log(sum21(1, 4))

console.log()
console.log('=======================================================1')
// 2.Void Undefined重要提示
const undefinedFun1 = (): undefined => {
  return undefined
}
const undefinedFun2 = (): undefined => {
  return
}

const voidFun1 = (): void => {
  return undefined
}
const voidFun2 = (): void => {
  return
}

console.log()
console.log('=======================================================2')
// 3.可选参数，默认参数
// ?:
function optionParamFun1(name: string, age?: number, address: string = '北京') {
  console.log(name, age, address)
}
optionParamFun1('张三', 18, '上海')

console.log()
console.log('=======================================================3')
// 4.函数重载(Overloaded Func)
function overloadFun(a: string, b: string): string
function overloadFun(a: number, b: number): number
function overloadFun(a: number | string, b: number | string) {
  if (typeof a === 'string' && typeof b === 'string') {
    return `${a} + ${b}`
  } else if (typeof a === 'number' && typeof b === 'number') {
    return a + b
  } else {
    throw new Error('参数类型不匹配')
  }
}

console.log(overloadFun('hello', 'world'))
console.log(5, 6)
